	// --= select the next pos movie in the movie list (prev/next) buttons
	function mymovies_move(pos)
	{

		var sel	= document.getElementById('movie_select');
		sindex	= sel.selectedIndex;

		btn_prev = document.getElementById('btn_prev');
		btn_next = document.getElementById('btn_next');

		if(sindex > 0 && pos == -1 || sindex < sel.options.length - 1 && pos == 1)
		{

			sel.selectedIndex = sindex + pos;

			// --= redefine due to bug in browser =--
			sindex	= sel.selectedIndex;

			// --= Debug =--
			window.status = sindex;



			if(sindex > 0 && sindex < sel.options.length - 1) // if the index is not on either end
			{
				btn_prev.disabled = false;
				btn_next.disabled = false;
			}
			else if(sindex > 0) // index is at end
			{
				btn_prev.disabled = false;
				btn_next.disabled = true;

				btn_prev.focus();
			}
			else // index is at start
			{
				btn_prev.disabled = true;
				btn_next.disabled = false;

				btn_next.focus();
			}

			// --= load the selection =--
			mymovies_save_change_movie(sel.value);

		}

		if(sel.options.length <= 1)
		{
			btn_prev.disabled = true;
			btn_next.disabled = true;

			btn_next.blur();
		}


	}

	function mymovies_check_ignore(check, disable)
	{

		if(check)
		{

			document.getElementById('submit').disabled = false;
			// --= disable rest of form =--

			if(disable) mymovies_disable_form(true);

		}
		else
		{

			document.getElementById('submit').disabled = true;
			// --= Enable rest of form =--
			if(disable) mymovies_disable_form(false);

		}

	}

	var mm_save_movie_id = 0;

	function mymovies_save_setmovie(movie_id)
	{

		mm_save_movie_id = movie_id

	}

	// loads a particular selected movie. Also is called when the page is loaded
	function mymovies_load_movie(movie_id)
	{

		movie_id = movie_id || mm_save_movie_id;

		// get the values from the hidden elements
		medium		= document.getElementById('medium['+ movie_id +']').value;
		format		= document.getElementById('format['+ movie_id +']').value;
		ratio		= document.getElementById('ratio['+ movie_id +']').value;
		language	= document.getElementById('language['+ movie_id +']').value.split('|');
		subtitle	= document.getElementById('subtitle['+ movie_id +']').value.split('|');
		sound		= document.getElementById('sound['+ movie_id +']').value.split('|');
		rating		= document.getElementById('rating['+ movie_id +']').value;

		comment		= document.getElementById('comment['+ movie_id +']').value;

		// set the form with the values we just got
		select_value(document.getElementById('dtls_medium'), medium);
		select_value(document.getElementById('dtls_format'), format);
		select_value(document.getElementById('dtls_ratio'), ratio);
		checkbox_check(document.getElementsByName('dtls_language[]'), language, true);
		checkbox_check(document.getElementsByName('dtls_subtitle[]'), subtitle, true);
		checkbox_check(document.getElementsByName('dtls_sound[]'), sound, true);
		radio_check(document.getElementsByName('dtls_rating'), rating);

		document.getElementById('dtls_comment').innerHTML = comment;

		mymovies_check_completed();

		return true;

	}

	// fired when the page is loaded. runs a number of things that need to be called when the page is loaded
	function mymovies_onload()
	{
		// lets figure out if the prev/next buttons need to be disabled
		if(document.getElementById('movie_select').options.length <= 1) {
			document.getElementById('btn_next').style.display = 'none';
			document.getElementById('btn_prev').style.display = 'none';
		}
		mymovies_load_movie();
	}

	function mymovies_save_change_movie(movie_id)
	{

		mymovies_save_details(mm_save_movie_id);

		mymovies_load_movie(movie_id);

		mymovies_save_setmovie(movie_id);

	}

	function m(id)
	{

		// --= Shortcut function =--
		mymovies_save_details(id);

	}

	function mymovies_save_details(movie_id)
	{

		// --= This function saves all the form elements into the selected movie_id's hidden fields =--

		// --= <select> values =--
		medium		= document.getElementById('dtls_medium').options[document.getElementById('dtls_medium').selectedIndex].value;
		format		= document.getElementById('dtls_format').options[document.getElementById('dtls_format').selectedIndex].value;
		ratio		= document.getElementById('dtls_ratio').options[document.getElementById('dtls_ratio').selectedIndex].value;

		// --= type="checkbox" values =--
		language	= checkbox_values(document.getElementsByName('dtls_language[]')).join('|');
		subtitle	= checkbox_values(document.getElementsByName('dtls_subtitle[]')).join('|');
		sound		= checkbox_values(document.getElementsByName('dtls_sound[]')).join('|');
		rating		= checkbox_values(document.getElementsByName('dtls_rating'));

		document.getElementById('medium['+ movie_id +']').value		= medium;
		document.getElementById('format['+ movie_id +']').value		= format;
		document.getElementById('ratio['+ movie_id +']').value		= ratio;
		document.getElementById('language['+ movie_id +']').value	= language;
		document.getElementById('subtitle['+ movie_id +']').value	= subtitle;
		document.getElementById('sound['+ movie_id +']').value		= sound;
		document.getElementById('rating['+ movie_id +']').value		= rating;

		document.getElementById('comment['+ movie_id +']').value		= replace(replace(document.getElementById('dtls_comment').value, '\n', '<br />'), '\r', '');

		mymovies_check_completed();

	}

	function mymovies_check_completed()
	{

		frm = document.frm_add;
		pass = true;

		if(document.getElementById('ignore').checked == false)
		{

			for(i = 0; i < frm.elements.length; i++)
			{

				if(frm.elements[i].type == 'hidden' && frm.elements[i].className != 'not_req')
				{

					if(frm.elements[i].value == '')
					{

						pass = false;

					}

				}

			}

		}

		mymovies_check_ignore(pass, false);

	}

	function mymovies_disable_form(dis)
	{

		frm = document.frm_add;

		frm.movie_select.disabled = dis;

		frm.dtls_medium.disabled	= dis;
		frm.dtls_format.disabled	= dis;
		frm.dtls_ratio.disabled		= dis;

		disable_checkbox(document.getElementsByName('dtls_language[]'), dis);
		disable_checkbox(document.getElementsByName('dtls_subtitle[]'), dis);
		disable_checkbox(document.getElementsByName('dtls_sound[]'), dis);

		disable_checkbox(document.getElementsByName('dtls_rating'), dis);

		frm.dtls_comment.disabled	= dis;

	}

function disable_checkbox(obj, dis)
{
	for(i = 0; i < obj.length; i++) {
		obj.item(i).disabled = dis;
	}
}

// This function will loop though the selected <select> object, and select the matching value
function select_value(obj, val)
{
	for(i = 0; i < obj.options.length; i++) {
		if(obj.options[i].value == val) {
			obj.options[i].selected = true;
		}
	}
}

// This function loops though a bunch of related checkbox items (defined with the same id/name) and returns the values in an array of the selected items
function checkbox_values(obj)
{
	ret = new Array();
	for(i = 0; i < obj.length; i++) {
		if(obj.item(i) && obj.item(i).checked) {
			ret[ret.length] = obj.item(i).value;
		}
	}
	return ret;
}

// This function loops though a bunch of related checkboxes, and checks if the value == one of the values or string values. If so it checks it.
function checkbox_check(obj, values, uncheck)
{
	for(i = 0; i < obj.length; i++) {
		if(obj.item(i) != null) {
			if(values.inArray(obj.item(i).value)) {
				obj.item(i).checked = true;
			} else if(uncheck) {
				obj.item(i).checked = false;
			}
		}
	}
}

function radio_check(obj, value)
{
	for(i = 0; i < obj.length; i++) {
		if(obj.item(i).value == value) {
			obj.item(i).checked = true;
		}
	}
}